<?php

namespace LRP\Utils;

/**
 * Class Sys
 *
 * PHP Version > 7.0
 *
 * @package LRP\Utils
 * @author  Jon
 * @link    https://gitee.com/joncc/long-running-processor
 */
class Sys
{
    /**
     * @return bool
     */
    public static function isWin()
    {
        return strpos(PHP_OS, 'WIN') !== false;
    }

    /**
     * @return bool
     */
    public static function isCli()
    {
        return PHP_SAPI == 'cli' ? true : false;
    }

    /**
     * @return mixed
     */
    public static function microTime()
    {
        return microtime(true);
    }

    /**
     * @return int
     */
    public static function getMemory()
    {
        return memory_get_usage();
    }

    /**
     * @return string
     */
    public static function phpCmd()
    {
        return exec('which php');
    }

    /**
     * @return string
     */
    public static function endOfFileCharacter()
    {
        return self::isWin() ? "\r\n" : "\n";
    }

    /**
     * @param int $secs
     */
    public static function alarm($secs = 120)
    {
        if (!self::isWin()) {
            pcntl_alarm($secs);
        }
    }
}